<template>
	<view>
		<van-cell-group title="课程信息">
			<van-field label="课程名称" :value="courseName" readonly>
			</van-field>
			<van-field label="教室" :value="classroom" readonly>
			</van-field>
			<van-field label="老师" :value="teacher" readonly>
			</van-field>
			<van-cell is-link @click="popChooseWeek" label="周数">
			</van-cell>
			<van-popup :show="chooseWeek" @close="closeChoose" round position="bottom" custom-style="height: 53%">
				<van-grid :column-num="5" :clickable="true" :border="false">
					<van-checkbox-group :value="_weeks" disabled>
						<van-grid-item v-for="value in 25" :key="value" custom-style="weekNum" use-slot>
							<van-checkbox :name="value+1">
								{{value+1}}
							</van-checkbox>
						</van-grid-item>
					</van-checkbox-group>
				</van-grid>
			</van-popup>
			<van-field label="周" :value="day" :readonly="forbidEdit">
			</van-field>
			<van-field label="节数" :value="jieshu" :readonly="forbidEdit">
			</van-field>
		</van-cell-group>
		<div style="margin-top: 310rpx;">
			<van-row>
				<div style="margin:0 auto;width:90%">
					<van-button type="primary" color="#006600" plain block @click="deleteCourse">
						删除
					</van-button>
				</div>
			</van-row>
		</div>
		<van-notify id="van-notify" />
	</view>
</template>

<script>
	import Notify from '../../wxcomponents/vant/dist/notify/notify';
	export default {
		data() {
			return {
				classroom: "",
				teacher: "",
				courseName: "",
				weeks: [],
				_weeks: [],
				chooseWeek: false,
				day: null,
				jieshu: null,

			}
		},
		onLoad() {
			let self = this

			uni.$on('courseInfo', (Info) => {
				console.log(Info)
				self.courseName = Info.courseName
				self.teacher = Info.teacher
				self.weeks = Info.weeks
				self.classroom = Info.classroom
				self.day = (Info.unit) % 7 + 1
				self.jieshu = parseInt((Info.unit) / 7) + 1
			})
			uni.$emit('Send')
			this._weeks = this.weeks.map(String)

		},
		onUnload() {
			uni.$off('courseInfo')
			uni.$off('Send')
		},
		methods: {

			deleteCourse() {
				var course = {
					"openid": wx.getStorageSync('openid'),
					"courseName": this.courseName,
					"classroom": this.classroom,
					"weeks": this.weeks,
					"day": this.day,
					"jieshu": this.jieshu,
					"teacher": this.teacher
				}
				uni.request({
					url: getApp().globalData.baseURL + "/course/deleteACourse",
					data: {
						"course": JSON.stringify(course)
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						uni.navigateBack()
					},
					fail: (err) => {
						Notify({
							type: 'danger',
							message: '删除课程失败',
							top: 64
						});
					}
				})
			},
			closeChoose(e) {
				this.chooseWeek = false
			},
			popChooseWeek(e) {
				this.chooseWeek = true
			},
			edit() {
				this.forbidEdit = false
			}
		}
	}
</script>

<style scoped>
	.editBtn {}

	.van-button--block {
		width: 90% !important
	}

	.weekNum {
		margin-top: 50rpx;
		height: 100rpx
	}
</style>
